/*
GANESHA - Reasoning on critical infrastructures affected by emergency situations
Copyright (c) 2010-2011, Information Eng. Research Unit - Univ. of Alcala
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package es.uah.cc.ie.ganesha.messaging.tso;

import es.uah.cc.ie.ganesha.GANESHAConfiguration;
import es.uah.cc.ie.ganesha.GANESHAModel;
import es.uah.cc.ie.ganesha.messaging.AlertMessage;
import es.uah.cc.ie.ganesha.ontologies.PersistentOntology;
import es.uah.cc.ie.ganesha.results.GANESHAResultEntry;
import es.uah.cc.ie.ganesha.results.GANESHAResults;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom.JDOMException;

/**
 * TSO processing example
 * @author ieru
 */
public class TSORunExample {

    public static void main(String[] args) {

        PersistentOntology.ONTOLOGY_WORK_WITH_FILES = true;

        GANESHAModel model = null;

        try {
            model = new GANESHAModel("model1", new GANESHAConfiguration("../PruebaEjecucion/config.xml"));
        } catch (JDOMException ex) {
            Logger.getLogger(TSORunExample.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(TSORunExample.class.getName()).log(Level.SEVERE, null, ex);
        }

        TSOSituationManager situationManager = new TSOSituationManager();
        situationManager.addMessageFromXML("C:/tso_barcelona.xml");
        //situationManager.addMessageFromXML("tso_paterna.xml");

        model.addSituation(situationManager);

        GANESHAResults result = model.infer();

        for (GANESHAResultEntry<AlertMessage> entry : result.getPotentialIncidents().getIncidents()) {
            System.out.println(entry.message.getIdentifier());
            ((TSOMessage) entry.message).writeToXMLFile("C:/" + entry.message.getIdentifier() + ".xml");
        }
    }
}
